package com.sky.mapper;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * The interface Category mapper.
 */
@Mapper
public interface CategoryMapper {


    /**
     * 分类分页查询
     *
     * @param cpqDTO the cpq dto
     * @return the list
     */
    List<Category> selectList(CategoryPageQueryDTO cpqDTO);

    /**
     * 根据类型查询分类
     *
     * @param type the type
     * @return the list
     */
    List<Category> selectListByType(@Param("type") Integer type);


    /**
     * 根据id删除分类
     *
     * @param id the id
     */
    @Delete("delete from category where id = #{id}")
    void deleteById(@Param("id") Long id);


    /**
     * 新增分类
     *
     * @param category the category
     */
    @Insert("insert into category(id, type, name, sort, status, create_time, update_time, create_user, update_user) values (#{id}," +
            "#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Category category);


    /**
     * 启用、禁用分类
     *
     * @param category the category
     */
    @Update("update category set status = #{status} ,update_time = #{updateTime} ,update_user = #{updateUser}  where id = #{id} ")
    void updateStatusById(Category category);


    /**
     * 判断分类名称是否唯一
     *
     * @param name the name
     * @return the integer
     */
    @Select("select count(*) from category where name = #{name}")
    Integer selectCountByName(@Param("name") String name);


    /**
     * 非我判断分类名称是否唯一
     *
     * @param name the name
     * @param id   the id
     * @return the integer
     */
    @Select("select count(*) from category where name = #{name} and id != #{id}")
    Integer selectCountByNameAndId(@Param("name") String name, @Param("id") Long id);


    /**
     * 更新数据
     *
     * @param category the category
     */
    void update(Category category);
}
